package jp.syuriken.snsw.terenaibot.mal.twitter;

import java.util.regex.Matcher;

import jp.syuriken.snsw.terenaibot.format.CompileArg;
import jp.syuriken.snsw.terenaibot.format.FormatPrefix;

/**
 * TODO snsoftware
 * 
 * @author $Author: snswinhaiku.lo@gmail.com $*/
public class MatcherFormatPrefix implements FormatPrefix {
	
	private final Matcher matcher;
	

	/**
	 * インスタンスを生成する。
	 * 
	 * @param matcher
	 */
	public MatcherFormatPrefix(Matcher matcher) {
		this.matcher = matcher;
	}
	
	@Override
	public String getString(CompileArg compileArg, String name) {
		try {
			int findGroup = Integer.valueOf(name);
			return matcher.group(findGroup);
		} catch (NumberFormatException e) {
			return null;
		} catch (IndexOutOfBoundsException e) {
			return null;
		}
	}
	
}
